package com.nike.util;



import java.util.UUID;

import javax.script.Invocable;
import javax.script.ScriptEngine;
import javax.script.ScriptEngineManager;

public class JSUtil {
	
	public static String GET_VISTOR_ID = "function getVisitorId(){for(var e=new Array(36),n=0;n<36;n++){e[n]='0123456789abcdef'.substr(Math.floor(16*Math.random()),1)}return e[14]='4',e[19]='0123456789abcdef'.substr(3&e[19]|8,1),e[8]=e[13]=e[18]=e[23]='-',e.join('')};";
	public static String getVisitorId() throws Exception{
		ScriptEngineManager manager = new ScriptEngineManager();
		ScriptEngine engine = manager.getEngineByName("javascript");
		engine.eval(GET_VISTOR_ID);
		Invocable invoke = (Invocable)engine;
		String c = (String)invoke.invokeFunction("getVisitorId");
		return c;
	}
	
	public static void main(String[] args) throws Exception{
		//0b67381d1ef9e63ccc78492b2d53e128
		System.out.println(JSUtil.getVisitorId());
		System.out.println(UUID.randomUUID().toString());
	}
	
}
